/*
ID: icerupt1
PROG: beads
LANG: C++11
*/
// run: $exec < beads.in
#include <fstream>
#include <algorithm>
#include <string>
using namespace std;

const int maxn = 702;
int forw[maxn][2]; //red 0  blue 1
int back[maxn][2];


int main()
{
	ofstream fout ("beads.out");
	ifstream fin ("beads.in");

	int l;
	fin >> l;
	string s;
	fin >> s;
	s += s;
	for (auto & i : s) (i == 'w')?i = 2:i = (i == 'b');

	int len = 2*l;
	if (s[0] != 1) forw[0][0] = 1;
	if (s[0] != 0) forw[0][1] = 1;
	for (int i = 1; i < len; i++) {
		if (s[i] == 2) {
			forw[i][0] = forw[i-1][0] + 1;
			forw[i][1] = forw[i-1][1] + 1;
		} else
		if (s[i] == s[i-1] || s[i-1] == 2)
			forw[i][int(s[i])] = forw[i-1][int(s[i])] + 1;
		else
			forw[i][int(s[i])] = 1;
	}

	if (s[len-1] != 1) back[len-1][0] = 1;
	if (s[len-1] != 0) back[len-1][1] = 1;
	for (int i = len-2; i >= 0; i--) {
		if (s[i] == 2) {
			back[i][0] = back[i+1][0] + 1;
			back[i][1] = back[i+1][1] + 1;
		} else
		if (s[i] == s[i+1] || s[i+1] == 2)
			back[i][int(s[i])] = back[i+1][int(s[i])] + 1;
		else
			back[i][int(s[i])] = 1;
	}
	int max_len = 0;
	for (int i = 0; i < len-1; i++) {
		max_len = max( max_len,
							max(forw[i][0], forw[i][1]) +
								max(back[i+1][0], back[i+1][1]) );
	}

	fout << min(max_len, l) << endl;
}
